package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
      @NamedQuery(name = "findAclSidById", query = "select myAclSid from AclSid myAclSid where myAclSid.id = ?1"),
      @NamedQuery(name = "findAclSidByPrimaryKey", query = "select myAclSid from AclSid myAclSid where myAclSid.id = ?1"),
      @NamedQuery(name = "findAclSidByType", query = "select myAclSid from AclSid myAclSid where myAclSid.type = ?1"),
      @NamedQuery(name = "findAclSidBySid", query = "select myAclSid from AclSid myAclSid where myAclSid.sid = ?1"),
      @NamedQuery(name = "findAclSidBySidContaining", query = "select myAclSid from AclSid myAclSid where myAclSid.sid like ?1"),
      @NamedQuery(name = "findAllAclSids", query = "select myAclSid from AclSid myAclSid") })
@Table(catalog = "sow", name = "acl_sid")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "AclSid")
@XmlRootElement(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain")
public class AclSid implements Serializable {
   private static final long serialVersionUID = 1L;

   /**
	 */

   @Column(name = "ID", nullable = false)
   @Basic(fetch = FetchType.EAGER)
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @XmlElement
   Integer id;
   /**
	 */

   @Column(name = "TYPE", length = 1, nullable = false)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   String type;
   /**
	 */

   @Column(name = "SID", length = 100, nullable = false)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   String sid;

   /**
	 */
   @OneToMany(mappedBy = "aclSid", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
   @XmlElement(name = "", namespace = "")
   java.util.Set<edu.hcmus.sow.domain.AclObjectIdentity> aclObjectIdentities;
   /**
	 */
   @OneToMany(mappedBy = "aclSid", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
   @XmlElement(name = "", namespace = "")
   java.util.Set<edu.hcmus.sow.domain.AclEntry> aclEntries;

   /**
	 */
   public void setId(Integer id) {
      this.id = id;
   }

   /**
	 */
   public Integer getId() {
      return this.id;
   }

   /**
	 */
   public void setType(String type) {
      this.type = type;
   }

   /**
	 */
   public String getType() {
      return this.type;
   }

   /**
	 */
   public void setSid(String sid) {
      this.sid = sid;
   }

   /**
	 */
   public String getSid() {
      return this.sid;
   }

   /**
	 */
   public void setAclObjectIdentities(Set<AclObjectIdentity> aclObjectIdentities) {
      this.aclObjectIdentities = aclObjectIdentities;
   }

   /**
	 */
   @JsonIgnore
   public Set<AclObjectIdentity> getAclObjectIdentities() {
      if (aclObjectIdentities == null) {
         aclObjectIdentities = new java.util.LinkedHashSet<edu.hcmus.sow.domain.AclObjectIdentity>();
      }
      return aclObjectIdentities;
   }

   /**
	 */
   public void setAclEntries(Set<AclEntry> aclEntries) {
      this.aclEntries = aclEntries;
   }

   /**
	 */
   @JsonIgnore
   public Set<AclEntry> getAclEntries() {
      if (aclEntries == null) {
         aclEntries = new java.util.LinkedHashSet<edu.hcmus.sow.domain.AclEntry>();
      }
      return aclEntries;
   }

   /**
	 */
   public AclSid() {
   }

   /**
    * Copies the contents of the specified bean into this bean.
    * 
    */
   public void copy(AclSid that) {
      setId(that.getId());
      setType(that.getType());
      setSid(that.getSid());
      setAclObjectIdentities(new java.util.LinkedHashSet<edu.hcmus.sow.domain.AclObjectIdentity>(
            that.getAclObjectIdentities()));
      setAclEntries(new java.util.LinkedHashSet<edu.hcmus.sow.domain.AclEntry>(that.getAclEntries()));
   }

   /**
    * Returns a textual representation of a bean.
    * 
    */
   public String toString() {

      StringBuilder buffer = new StringBuilder();

      buffer.append("id=[").append(id).append("] ");
      buffer.append("type=[").append(type).append("] ");
      buffer.append("sid=[").append(sid).append("] ");

      return buffer.toString();
   }

   /**
	 */
   @Override
   public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
      return result;
   }

   /**
	 */
   public boolean equals(Object obj) {
      if (obj == this)
         return true;
      if (!(obj instanceof AclSid))
         return false;
      AclSid equalCheck = (AclSid) obj;
      if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
         return false;
      if (id != null && !id.equals(equalCheck.id))
         return false;
      return true;
   }
}
